In [29]:
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from datetime import datetime
import seaborn as sns
In [30]:
df = []
df = pd.read_csv('dataset_2018.csv')
df.head()
Out[30]:
State/UTs Crime Head Year Revenge /Settling scores Greed/ Money Extortion Cause Disrepute Prank/ Satisfaction of Gaining Control Fraud/ Illegal Gain Eve teasing/ Harassment Others Total
0 Andhra Pradesh Cyber Crimes By Motives 2018 7 63 0 0 0 219 225 137 651
1 Arunachal Pradesh Cyber Crimes By Motives 2018 0 0 0 0 0 0 0 10 10
2 Assam Cyber Crimes By Motives 2018 0 0 0 0 0 0 0 154 154
3 Bihar Cyber Crimes By Motives 2018 0 135 0 3 0 0 0 1 139
4 Chhattisgarh Cyber Crimes By Motives 2018 0 0 2 0 0 4 17 78 101
In [31]:
df.columns = df.columns.str.replace('\/','') 
df.head()
Out[31]:
StateUTs Crime Head Year Revenge Settling scores Greed Money Extortion Cause Disrepute Prank Satisfaction of Gaining Control Fraud Illegal Gain Eve teasing Harassment Others Total
0 Andhra Pradesh Cyber Crimes By Motives 2018 7 63 0 0 0 219 225 137 651
1 Arunachal Pradesh Cyber Crimes By Motives 2018 0 0 0 0 0 0 0 10 10
2 Assam Cyber Crimes By Motives 2018 0 0 0 0 0 0 0 154 154
3 Bihar Cyber Crimes By Motives 2018 0 135 0 3 0 0 0 1 139
4 Chhattisgarh Cyber Crimes By Motives 2018 0 0 2 0 0 4 17 78 101
In [32]:
df = df.drop(df[df.StateUTs == 'Total (UTs)'].index)
df = df.drop(df[df.StateUTs == 'Total (States)'].index)
df = df.drop(df[df.StateUTs == 'Total (All India)'].index)
In [33]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
sns.barplot(x='StateUTs', y='Total', data = df)
plt.title('Cyber Crimes - Total')
plt.ylabel('Total')
plt.xticks(rotation=90)
Out[33]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34]), <a list of 35 Text xticklabel objects>)
In [34]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
yCol = 'Revenge Settling scores'
sns.barplot(x='StateUTs', y = yCol, data = df)
plt.title('Cyber Crimes - ' + yCol)
plt.ylabel('Total')
plt.xticks(rotation=90)
Out[34]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34]), <a list of 35 Text xticklabel objects>)
In [35]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
yCol = 'Greed Money'
sns.barplot(x='StateUTs', y = yCol, data = df)
plt.title('Cyber Crimes - ' + yCol)
plt.ylabel('Total')
plt.xticks(rotation=90)
Out[35]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34]), <a list of 35 Text xticklabel objects>)
In [36]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
yCol = 'Extortion'
sns.barplot(x='StateUTs', y = yCol, data = df)
plt.title('Cyber Crimes - ' + yCol)
plt.ylabel('Total')
plt.xticks(rotation=90)
Out[36]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34]), <a list of 35 Text xticklabel objects>)
In [37]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
yCol = 'Cause Disrepute'
sns.barplot(x='StateUTs', y = yCol, data = df)
plt.title('Cyber Crimes - ' + yCol)
plt.ylabel('Total')
plt.xticks(rotation=90)
Out[37]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34]), <a list of 35 Text xticklabel objects>)
In [38]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
yCol = 'Prank Satisfaction of Gaining Control '
sns.barplot(x='StateUTs', y = yCol, data = df)
plt.title('Cyber Crimes - ' + yCol)
plt.ylabel('Total')
plt.xticks(rotation=90)
Out[38]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34]), <a list of 35 Text xticklabel objects>)
In [39]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
yCol = 'Fraud Illegal Gain'
sns.barplot(x='StateUTs', y = yCol, data = df)
plt.title('Cyber Crimes - ' + yCol)
plt.ylabel('Total')
plt.xticks(rotation=90)
Out[39]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34]), <a list of 35 Text xticklabel objects>)
In [40]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
yCol = 'Eve teasing Harassment'
sns.barplot(x='StateUTs', y = yCol, data = df)
plt.title('Cyber Crimes - ' + yCol)
plt.ylabel('Total')
plt.xticks(rotation=90)
Out[40]:
(array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
        34]), <a list of 35 Text xticklabel objects>)
In [41]:
df_new = df
df_new = df_new.drop(['Crime Head','Total'], axis = 1)
df_new = pd.melt(df_new, id_vars=['StateUTs','Year'], var_name = 'CrimeType')
df_new.head()
Out[41]:
StateUTs Year CrimeType value
0 Andhra Pradesh 2018 Revenge Settling scores 7
1 Arunachal Pradesh 2018 Revenge Settling scores 0
2 Assam 2018 Revenge Settling scores 0
3 Bihar 2018 Revenge Settling scores 0
4 Chhattisgarh 2018 Revenge Settling scores 0
In [42]:
df_totalCrimeType = pd.DataFrame({'TotalCrimes' : df_new.groupby(['CrimeType']).value.sum()}).reset_index()
df_totalCrimeType
Out[42]:
CrimeType TotalCrimes
0 Cause Disrepute 148
1 Eve teasing Harassment 1116
2 Extortion 73
3 Fraud Illegal Gain 1240
4 Greed Money 821
5 Others 2144
6 Prank Satisfaction of Gaining Control 39
7 Revenge Settling scores 112
In [43]:
plt.figure(figsize=(70,30))
sns.set(font_scale=6)
sns.barplot(x='CrimeType', y='TotalCrimes', data=df_totalCrimeType)
plt.title('Cyber Crimes - Overall')
plt.xlabel('Type of Crime')
plt.ylabel('Total Crimes')
plt.xticks(rotation=90)
Out[43]:
(array([0, 1, 2, 3, 4, 5, 6, 7]), <a list of 8 Text xticklabel objects>)
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: